package com.yhp.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.system.common.mapper.BisNurseProjectMapper;
import com.system.common.pojo.BisNurseProject;
import com.system.common.pojo.BisNurseProjectExample;
import com.system.common.pojo.BisNurseProjectExample.Criteria;

@Service
public class FrontBisNurseProjectServiceImpl implements FrontBisNurseProjectService {

	@Autowired
	private BisNurseProjectMapper bisNurseProjectMapper;

	/**
	 * 综合查询
	 */
	@Override
	public List<BisNurseProject> selectByExample(Map<String, Object> map) {String projectId = (String) map.get("projectId");
	String projectName = (String) map.get("projectName");
	String rmbPrice1 = (String) map.get("rmbPrice1");
	String rmbPrice2 = (String) map.get("rmbPrice2");
	BisNurseProjectExample example = new BisNurseProjectExample();
	Criteria criteria = example.createCriteria(); // 初始化一个查询条件
	if (StringUtils.isNotBlank(projectName)) {
		criteria.andProjectNameLike("%" + projectName + "%");
	}
	if (StringUtils.isNotBlank(projectId)) {
		criteria.andProjectIdEqualTo(projectId);
	}
	if (StringUtils.isNotBlank(rmbPrice1)&&rmbPrice2==null) {
		criteria.andRmbPriceGreaterThanOrEqualTo(Double.parseDouble(rmbPrice1));
	}
	if (StringUtils.isNotBlank(rmbPrice2)&&rmbPrice1==null) {
		criteria.andRmbPriceLessThanOrEqualTo(Double.parseDouble(rmbPrice2));
	}
	if (StringUtils.isNotBlank(rmbPrice1)&&StringUtils.isNotBlank(rmbPrice2)) {
		criteria.andRmbPriceGreaterThanOrEqualTo(Double.parseDouble(rmbPrice1));
		criteria.andRmbPriceLessThanOrEqualTo(Double.parseDouble(rmbPrice2));
	}
	List<BisNurseProject> selectByExample = this.bisNurseProjectMapper.selectByExample(example);
	List<BisNurseProject> bisNurseProjectList=new ArrayList<>();
	for (BisNurseProject bisNurseProject : selectByExample) {
		if (bisNurseProject.getIsDel().equals("0")&&bisNurseProject.getStatus().equals("1")) {
			bisNurseProjectList.add(bisNurseProject);
		}
	}
	return bisNurseProjectList;}

	/**
	 * 根据ID单个查询
	 */
	@Override
	public BisNurseProject selectByPrimaryKey(String projectId) {
		return bisNurseProjectMapper.selectByPrimaryKey(projectId);
	}
}
